package charpter01_basic.lession04_wait_notify_notifyall;

import java.util.LinkedList;
import java.util.Queue;

public class BlockingQueue implements MyBlockingQueue {

    Queue<String> buffer = new LinkedList<>();

    public synchronized void give(String data) {
        buffer.add(data);
        notify();  // Since someone may be waiting in take
    }

    public synchronized String take() throws InterruptedException {
        while (buffer.isEmpty()) {
            wait();
        }
        return buffer.remove();
    }
}
